﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{

    [Table(Name = "dbo.ExamPaper")]
    public partial class ExamPaper : Entity
    {

        private decimal _examNum;

        private decimal _kmNum;

        private string _examName;

        private float _totalScore;

        private float _eligibleScore;

        private DateTime _examVer;

        private string _examType;

        private int _timeOver;

        private bool _bFB;

        private EntitySet<TX> _TX;

        private EntityRef<KM> _KM;

        public ExamPaper()
        {
            this._TX = new EntitySet<TX>(new Action<TX>(this.attach_TX), new Action<TX>(this.detach_TX));
            this._KM = default(EntityRef<KM>);
        }

        [Column(Storage = "_examNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal ExamNum
        {
            get
            {
                return this._examNum;
            }
            set
            {
                if ((this._examNum != value))
                {
                    this.SendPropertyChanging("ExamNum");
                    this._examNum = value;
                    this.SendPropertyChanged("ExamNum",value);
                }
            }
        }

        [Column(Storage = "_kmNum", DbType = "Decimal(18,0)")]
        public decimal KMNum
        {
            get
            {
                return this._kmNum;
            }
            set
            {
                if ((this._kmNum != value))
                {
                    if (this._KM.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("KMNum");
                    this._kmNum = value;
                    this.SendPropertyChanged("KMNum",value);
                }
            }
        }

        [Column(Storage = "_examName", DbType = "VarChar(200) NOT NULL", CanBeNull = false)]
        public string ExamName
        {
            get
            {
                return this._examName;
            }
            set
            {
                if ((this._examName != value))
                {
                    this.SendPropertyChanging("ExamName");
                    this._examName = value;
                    this.SendPropertyChanged("ExamName",value);
                }
            }
        }

        [Column(Storage = "_totalScore", DbType = "Real NOT NULL")]
        public float TotalScore
        {
            get
            {
                return this._totalScore;
            }
            set
            {
                if ((this._totalScore != value))
                {
                    this.SendPropertyChanging("TotalScore");
                    this._totalScore = value;
                    this.SendPropertyChanged("TotalScore",value);
                }
            }
        }

        [Column(Storage = "_eligibleScore", DbType = "Real NOT NULL")]
        public float EligibleScore
        {
            get
            {
                return this._eligibleScore;
            }
            set
            {
                if ((this._eligibleScore != value))
                {
                    this.SendPropertyChanging("EligibleScore");
                    this._eligibleScore = value;
                    this.SendPropertyChanged("EligibleScore",value);
                }
            }
        }

        [Column(Storage = "_examVer", DbType = "DateTime NOT NULL")]
        public DateTime ExamVer
        {
            get
            {
                return this._examVer;
            }
            set
            {
                if ((this._examVer != value))
                {
                    this.SendPropertyChanging("ExamVer");
                    this._examVer = value;
                    this.SendPropertyChanged("ExamVer",value);
                }
            }
        }

        [Column(Storage = "_examType", DbType = "VarChar(50)")]
        public string ExamType
        {
            get
            {
                return this._examType;
            }
            set
            {
                if ((this._examType != value))
                {
                    this.SendPropertyChanging("ExamType");
                    this._examType = value;
                    this.SendPropertyChanged("ExamType",value);
                }
            }
        }

        [Column(Storage = "_timeOver", DbType = "Int")]
        public int TimeOver
        {
            get
            {
                return this._timeOver;
            }
            set
            {
                if ((this._timeOver != value))
                {
                    this.SendPropertyChanging("TimeOver");
                    this._timeOver = value;
                    this.SendPropertyChanged("TimeOver",value);
                }
            }
        }

        [Column(Storage = "_bFB", DbType = "Bit")]
        public bool bFB
        {
            get
            {
                return this._bFB;
            }
            set
            {
                if ((this._bFB != value))
                {
                    this.SendPropertyChanging("bFB");
                    this._bFB = value;
                    this.SendPropertyChanged("bFB",value);
                }
            }
        }

        [Association(Name = "ExamPaper_TX", Storage = "_TX", ThisKey = "ExamNum", OtherKey = "ExamNum")]
        public EntitySet<TX> TX
        {
            get
            {
                return this._TX;
            }
            set
            {
                this._TX.Assign(value);
            }
        }

        [Association(Name = "KM_ExamPaper", Storage = "_KM", ThisKey = "KMNum", OtherKey = "KMNum", IsForeignKey = true)]
        public KM KM
        {
            get
            {
                return this._KM.Entity;
            }
            set
            {
                KM previousValue = this._KM.Entity;
                if (((previousValue != value)
                            || (this._KM.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("KM");
                    if ((previousValue != null))
                    {
                        this._KM.Entity = null;
                        previousValue.ExamPaper.Remove(this);
                    }
                    this._KM.Entity = value;
                    if ((value != null))
                    {
                        value.ExamPaper.Add(this);
                        this._kmNum = value.KMNum;
                    }
                    else
                    {
                        this._kmNum = default(decimal);
                    }
                    this.SendPropertyChanged("KM",value);
                }
            }
        }

        private void attach_TX(TX entity)
        {
            entity.ExamPaper = this;
        }

        private void detach_TX(TX entity)
        {
            entity.ExamPaper = null;
        }
    }
}
